<template>
  <div class="m-equipment-detail">
    <!-- 设备title、设备ID、所在省份、所在市区、围观次数、备注 -->
    <div class="header-view">
      <el-image class="equipment-img" fit="cover" :src="equipmentUrl" :preview-src-list="[equipmentUrl]" lazy :alt="equipmentDetail.title"></el-image>
      <div class="info-right m-container">
        <div class="info-title">{{ equipmentDetail.title }}</div>
        <div class="info-tag" v-if="locale == 'zh-CN'">
          <p v-for="item in equipmentDetail.targerList" :key="item">{{ item }}</p>
        </div>
        <div style="height: 18px" v-else></div>
        <div class="info-use">
          <div class="use-item" :style="{ width: locale == 'en-US' ? '100%' : '50%' }">
            <p>{{ $t("equipmentId") }}</p>
            <span>{{ equipmentDetail.id }}</span>
          </div>
          <div class="use-item" v-if="locale == 'zh-CN'">
            <p>所在市区</p>
            <span>{{ equipmentDetail.cityName }}</span>
          </div>
          <div class="use-item" v-if="locale == 'zh-CN'">
            <p>所在省份</p>
            <span>{{ equipmentDetail.provinceName }}</span>
          </div>
          <div class="use-item" :style="{ width: locale == 'en-US' ? '100%' : '50%' }">
            <p>{{ $t("observationFrequency") }}</p>
            <span>{{ equipmentDetail.pv }}</span>
          </div>
        </div>
        <div class="info-care" v-if="locale == 'zh-CN'">备注：{{ equipmentDetail.remark || "暂无备注说明" }}</div>
      </div>
    </div>
    <!-- 基本信息 -->
    <div class="base-view m-container">
      <div class="view-title">{{ $t("basicInformation") }}</div>
      <div class="archives-list">
        <div
          class="list-item"
          :style="{ width: locale == 'en-US' ? '100%' : '50%' }"
          v-for="item in baseInfo.attrs"
          :key="item.title"
          v-show="item.subType != 20203"
        >
          <p>{{ item.title }}</p>
          <span>{{ item.tempValue ? (item.tempValue == "不详" && locale == "en-US" ? "unknown" : item.tempValue) : "--" }}</span>
        </div>
      </div>
    </div>
    <!-- 设备图片 -->
    <div class="m-container" v-for="item in photoList" :key="item.cardTitle">
      <div class="view-title">{{ item.cardTitle }}</div>
      <div class="photo-list">
        <div class="photo-item" v-for="(itemNew, index) in item.attrs" :key="index">
          <el-image
            class="img-url"
            fit="cover"
            :src="itemNew.map.thumbUrl"
            :preview-src-list="[itemNew.map.url]"
            lazy
            :alt="`${equipmentDetail.title}-${itemNew.title}`"
          />
          <p class="photo-info">{{ itemNew.title }}</p>
        </div>
      </div>
    </div>
    <!-- 设备视频 -->
    <div class="m-container" v-if="videoList.length">
      <div class="view-title">{{ $t("deviceVideo") }}</div>
      <div class="photo-list">
        <div class="photo-item" v-for="(item, index) in videoList" :key="index">
          <client-only>
            <vueMiniPlayer ref="vueMiniPlayer" :video="item" :mutex="true" @fullscreen="handleFullscreen" />
          </client-only>
        </div>
      </div>
    </div>
    <!-- 设备推荐 -->
    <div class="view-title m-container" v-if="recommendList.length">{{ $t("recommendedGoodCars") }}</div>
    <section class="recommend-list m-container" v-if="recommendList.length">
      <a
        class="equipment-item"
        v-for="item in recommendList"
        :key="item.crmEquipmentId"
        :href="`/m-equipment/${item.typeNameEn}-${item.crmEquipmentId}`"
        :title="`${item.title} | ${item.subHeading}`"
      >
        <el-image class="info-img" fit="cover" :src="item.thumbnail" lazy :alt="item.title"></el-image>
        <div class="info-bottom">
          <div class="info-title">{{ item.title }}</div>
          <div class="info-year">{{ item.subHeading }}</div>
          <div class="info-tag" v-if="locale == 'zh-CN'">
            <p v-for="val in item.targerList" :key="val">{{ val }}</p>
          </div>
          <div style="height: 18px" v-else></div>
          <div class="info-price">
            <template v-if="item.crmEquipmentFixedPriceId && item.offlineBargaining != 1">
              <p v-if="locale == 'en-US'">CNY{{ item.startingPriceNotag }}</p>
              <p v-else>{{ item.startingPrice / 1000000 }}万</p>
            </template>
            <p v-else>{{ $t("priceNegotiable") }}</p>
          </div>
        </div>
      </a>
    </section>
    <!-- WhatsApp -->
    <!-- <WhatsAppM v-if="locale == 'en-US'" /> -->
    <!-- 底部信息 -->
    <FooterM></FooterM>
  </div>
</template>

<script>
import { mapState } from "vuex"
import BigNumber from "bignumber.js"
export default {
  name: "EquipmentDetail",
  layout: "mobile",
  data() {
    return {}
  },
  head() {
    return {
      title: `【${this.equipmentDetail.title}】-${this.equipmentDetail.cityName}${this.equipmentDetail.title}${this.$i18n.t("detailHeadTitle")}`,
      meta: [
        {
          hid: "keywords",
          name: "keywords",
          content: `${this.equipmentDetail.title}，${this.equipmentDetail.title}${this.$i18n.t("haeaKeySell")}，${
            this.equipmentDetail.title
          }${this.$i18n.t("haeaKeyPrice")}`
        },
        {
          hid: "description",
          name: "description",
          content: `${this.$i18n.t("haeaDecProvide")}${this.equipmentDetail.cityName}${this.equipmentDetail.title}${this.$i18n.t("haeaDecTransfer")}${
            this.equipmentDetail.workingHours > 0 ? this.equipmentDetail.workingHours : this.$i18n.t("haeaDecUnknown")
          }${this.$i18n.t("haeaDecCondition")}${this.equipmentDetail.title}${this.$i18n.t("haeaDecChoose")}`
        }
      ]
    }
  },
  async asyncData({ app, params }) {
    let paramsRes = params.detailParams.split("-")
    console.log("paramsRes", paramsRes)
    let id = paramsRes[1] //设备ID
    let equipmentDetail = {}
    let equipmentUrl = ""
    let baseInfo = {}
    let photoList = []
    let videoList = []
    let recommendList = []
    try {
      // 设备详情
      let detailRes = await app.$api.equipmentDetail({ id })
      let detail = detailRes.data
      detail["targerList"] = app.$optionsData.parseLabel(detail)
      equipmentDetail = detail
      let cardList = detail.equipmentDetailsConfig.cardList
      baseInfo = cardList.filter((v) => v.type == 202)[0] //基本信息
      photoList = cardList.filter((v) => v.type == 204) //设备照片
      equipmentUrl = photoList.length ? photoList[0].attrs[0].map.url : ""
      let videoInfo = cardList.filter((v) => v.type == 205)[0] //设备视频
      videoList = []
      videoInfo &&
        videoInfo.attrs.map((item) => {
          let b = {
            url: item.map.originVideo,
            cover: item.map.videoThumbUrl,
            muted: false,
            loop: false,
            preload: "auto",
            poster: "",
            autoplay: false,
            playsinline: false,
            logo: "SANY",
            format: item.format,
            title: item.title
          }
          videoList.push(b)
        })
      baseInfo.attrs.map((item) => {
        if (item.subType === 20201) {
          if (Object.values(item.map)[0] != "-1" && Object.values(item.map)[0] != "0" && Object.values(item.map)[0]) {
            item["tempValue"] = Object.values(item.map)[0] + item.placeholder.split("{0}")[1]
          } else {
            if (Object.values(item.map)[0] == null || Object.values(item.map)[0] == "") {
              item["tempValue"] = ""
            } else {
              item["tempValue"] = "不详"
            }
          }
        }
        if (item.subType === 20202) {
          let key = Object.values(item.map)[0]
          item.options.forEach((one) => {
            if (one.value === key) {
              item["tempValue"] = one.name
            }
          })
        }
      })
      // 好车推荐
      let recommendRes = await app.$api.equipmentRecommend({ equipmentId: id, limit: 8 })
      let list = recommendRes.data
      list.map((item) => {
        item.startingPriceNotag = new BigNumber(item.startingPrice).dividedBy(100).toFormat()
        let targerList = app.$optionsData.parseLabel(item)
        targerList = targerList.splice(0, 2)
        item["targerList"] = targerList
        return item
      })
      recommendList = list
    } catch (error) {
      console.log("error", error)
    }
    return {
      equipmentDetail, //设备详情
      equipmentUrl, //设备url
      baseInfo, //基础信息
      photoList, //设备照片
      videoList, //设备视频
      recommendList //设备列表
    }
  },
  props: {},
  computed: { ...mapState(["locale"]) },
  watch: {},
  async mounted() {
    this.$cookies.set("msgInfo", true) //缓存检索存储值
    this.getPoint()
  },
  methods: {
    handleFullscreen(data) {
      console.log("data", data)
    },
    async getPoint() {
      let params = await this.$optionPoint.sendUrl(window, navigator, document)
      this.$api.burySave({ ...params }).then((res) => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.m-equipment-detail {
  .header-view {
    margin-top: 225px;
    .equipment-img {
      width: 100%;
      height: 1260px;
      display: block;
    }
    .info-right {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      margin-top: 87px;
      .info-title {
        font-family: PingFangSC, PingFang SC;
        font-weight: 500;
        font-size: 113px;
        color: #333;
        line-height: 123px;
      }
      .info-tag {
        display: flex;
        align-items: center;
        margin: 50px 0;
        p {
          height: 92px;
          line-height: 92px;
          padding: 10px 20px;
          border-radius: 4px;
          font-size: 50px;
          font-weight: 400;
          color: #fb463f;
          background: rgba(251, 70, 63, 0.08);
          margin-right: 30px;
        }
      }
      .info-use {
        width: 100%;
        height: 343px;
        background: #f6f7f9;
        padding: 50px;
        box-sizing: border-box;
        display: flex;
        flex-wrap: wrap;
        .use-item {
          width: 50%;
          display: flex;
          align-items: center;
          p {
            min-width: 300px;
            font-size: 72px;
            font-weight: 500;
            color: #999;
            line-height: 82px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
          span {
            font-family: PingFangSC, PingFang SC;
            font-weight: 500;
            font-size: 72px;
            color: #333;
            line-height: 82px;
            margin-left: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
      .info-care {
        width: 100%;
        height: 100%;
        background: #f6f7f9;
        padding: 50px;
        box-sizing: border-box;
        font-family: PingFangSC, PingFang SC;
        font-weight: 600;
        font-size: 67px;
        color: #666666;
        line-height: 102px;
        margin-top: 50px;
      }
    }
  }
  .view-title {
    font-family: PingFangSC, PingFang SC;
    font-weight: 500;
    font-size: 87px;
    color: #333;
    line-height: 87px;
    margin-top: 60px;
    margin-bottom: 90px;
  }
  .base-view {
    margin-top: 60px;
    margin-bottom: 10px;
    .archives-list {
      display: flex;
      flex-wrap: wrap;
      .list-item {
        display: flex;
        align-items: center;
        margin-bottom: 90px;
        p {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 72px;
          color: #999;
          line-height: 72px;
          flex-shrink: 0;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        span {
          font-family: PingFangSC, PingFang SC;
          font-weight: 500;
          font-size: 72px;
          color: #333;
          line-height: 72px;
          margin-left: 30px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }
  }
  .photo-list {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .photo-item {
      width: 400px;
      height: 400px;
      margin-bottom: 60px;
      position: relative;
      .img-url {
        width: 100%;
        height: 100%;
        display: block;
      }
      .photo-info {
        width: 100%;
        padding: 20px 5px;
        box-sizing: border-box;
        text-align: center;
        background: rgba(0, 0, 0, 0.5);
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 50px;
        color: #fff;
        position: absolute;
        left: 0;
        bottom: 0;
      }
      &:last-child:nth-child(4n - 1) {
        margin-right: calc(24% + 4% / 3);
      }
      &:last-child:nth-child(4n - 2) {
        margin-right: calc(48% + 8% / 3);
      }
    }
  }
  .recommend-list {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .equipment-item {
      width: 860px;
      height: 100%;
      margin-bottom: 50px;
      .info-img {
        width: 860px;
        height: 543px;
        display: block;
      }
      .info-bottom {
        width: 100%;
        height: 486px;
        background: #f6f7f9;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 50px;
        box-sizing: border-box;
        .info-title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 500;
          font-size: 72px;
          color: #333;
          line-height: 92px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .info-year {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 60px;
          color: #999;
          line-height: 80px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .info-tag {
          display: flex;
          align-items: center;
          p {
            height: 60px;
            line-height: 60px;
            padding: 10px;
            border-radius: 12px;
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            font-size: 40px;
            color: #fb463f;
            background: rgba(251, 70, 63, 0.08);
            margin-right: 30px;
          }
        }
        .info-price {
          display: flex;
          align-items: flex-end;
          flex-direction: row;
          justify-content: space-between;
          p {
            font-size: 82px;
            font-weight: 700;
            color: #fb463f;
          }
        }
      }
    }
  }
}
::v-deep .vm-player {
  min-height: 0;
  ._play-btn {
    width: 150px;
    height: 150px;
    z-index: 1;
  }
  ._logo {
    top: 20px;
    right: 20px;
    z-index: 0;
  }
  .qun-base-controls {
    display: none;
  }
}
</style>
